/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import * as echarts from 'echarts'
export default function (data) {
  return {
    grid: {
      left: '0',
      right: '0'
    },
    backgroundColor: '#fff',
    angleAxis: {
      show: false,
      max: (100 * 360) / 180, // -45度到225度，二者偏移值是270度除360度
      type: 'value',
      startAngle: 180, // 极坐标初始角度
      splitLine: {
        show: false
      }
    },
    barMaxWidth: 50, // 圆环宽度
    radiusAxis: {
      show: false,
      type: 'category'
    },
    // 圆环位置和大小
    polar: {
      center: ['50%', '50%'],
      radius: '150%'
    },
    series: [
      {
        type: 'bar',
        stack: '测试',
        data: [
          {
            // 上层圆环，显示数据
            value: data,
            name: 'sdfasdf',
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                {
                  offset: 0,
                  color: '#E6DEFF'
                },

                {
                  offset: 1,
                  color: '#33327E'
                }
              ])
            }
          }
        ],
        barWidth: 26,
        coordinateSystem: 'polar',
        roundCap: true,
        z: 3
      },
      {
        type: 'bar',
        // stack: '测试',
        data: [
          {
            // 上层圆环，显示数据
            value: 100,
            name: 'sdfasdf',
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                {
                  offset: 0,
                  color: '#fff'
                },

                {
                  offset: 1,
                  color: 'rgb(153,116,255)'
                }
              ])
            }
          }
        ],
        barWidth: 25,
        coordinateSystem: 'polar',
        roundCap: true,
        z: 2

      },
      {
        // 下层圆环，显示最大值
        type: 'bar',
        data: [
          {
            value: 100,
            itemStyle: {
              color: {
                // 图形渐变颜色方法，四个数字分别代表，右，下，左，上，offset表示0%到100%
                type: 'linear',
                colorStops: [
                  {
                    offset: 0,
                    color: '#fff'
                  },
                  {
                    offset: 1,
                    color: '#CDB4FF'
                  }
                ]
              }
            }
          }
        ],
        barWidth: 30,
        coordinateSystem: 'polar',
        roundCap: true,
        z: 1
      },
      {
        stack: '测试',
        type: 'bar',
        data: [0.01],
        showBackground: false,
        coordinateSystem: 'polar',
        roundCap: true,
        z: 100,
        barWidth: 10,
        barGap: '-90%', // 柱间距离,上下两层圆环重合
        itemStyle: {
          color: '#33317E',
          borderColor: '#fff',
          borderWidth: 8,
          shadowColor: 'rgba(0,0,0,0.25)',
          shadowBlur: 15,
          shadowOffsetY: 0
        }
      },
      {
        name: '数据',
        type: 'gauge',
        //  center: ['20%', '50%'],
        radius: '75%',
        startAngle: 180,
        endAngle: 0,
        axisLine: {
          show: false
        },
        // 仪表盘文字
        axisLabel: {
          show: true,
          textStyle: {
            fontSize: 8,
            color: '#33317E'
          }
        }, // 刻度标签。
        axisTick: {
          show: false
        }, // 刻度样式
        splitLine: {
          show: false
        }, // 分隔线样式
        detail: {
          show: false
        },
        title: {
          show: true,
          offsetCenter: [0, '0%'],
          textStyle: {
            fontSize: 40,
            color: '#000000',
            fontWeight: 400
          }
        },
        data: [
          {
            value: data,
            name: parseInt(data) + '%'
          }
        ],
        // 箭头
        pointer: {
          icon: 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z',
          length: '5%',
          width: 10,
          offsetCenter: [0, '-68%'],
          itemStyle: {
            color: 'inherit'
          }
        }
      }
      // {
      //   name: '名称',
      //   type: 'gauge',
      //   //  center: ['20%', '50%'],
      //   radius: '70%',
      //   axisLine: {
      //     show: false
      //   },
      //   // 仪表盘文字
      //   axisLabel: {
      //     show: false
      //   }, // 刻度标签。
      //   axisTick: {
      //     show: false
      //   }, // 刻度样式
      //   splitLine: {
      //     show: false
      //   }, // 分隔线样式
      //   detail: {
      //     show: false
      //   },
      //   pointer: {
      //     show: false
      //   },
      //   title: {
      //     show: true,
      //     offsetCenter: ['0%', '52%'],
      //     textStyle: {
      //       fontSize: 30,
      //       color: '#000000',
      //       fontWeight: 400
      //     }
      //   },
      //   data: [
      //     {
      //       // value: 100,
      //       name: 'cpuUsage'
      //     }
      //   ]
      // }

    ]
  }
}
